Skip to content

Conversation

@FranckLecuyer
Copy link
Contributor

@FranckLecuyer FranckLecuyer commented Jan 28, 2026

PR Summary

Get all modifications to apply with only one rest call to the network-modification-server

should be merged together with : gridsuite/network-modification-server#757

…-modification-server

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

Replaced multiple per-UUID REST calls with a single batched GET to /v1/network-composite-modifications/network-modifications, passing UUIDs as repeated uuids query parameters and returning the resulting array of ModificationInfos as a List (or an empty list for no input).

Changes

Cohort / File(s) Summary
REST service & tests
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java, monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestServiceTest.java
Replaced iterative per-UUID requests with one batched GET to /v1/network-composite-modifications/network-modifications?uuids=...&onlyMetadata=false. Removed per-UUID accumulation, added CollectionUtils not-empty check, converted response array to List (or List.of() if empty), updated tests to expect combined uuids query params, and removed unused imports.

Sequence Diagram(s)

sequenceDiagram
    rect rgba(200,200,255,0.5)
    participant Caller
    end
    rect rgba(200,255,200,0.5)
    participant NetworkModificationRestService as Service
    end
    rect rgba(255,200,200,0.5)
    participant RemoteAPI as Remote Server
    end

    Caller->>Service: getModifications(List<UUID> uuids)
    Service->>RemoteAPI: GET /v1/network-composite-modifications/network-modifications?uuids=...&onlyMetadata=false
    RemoteAPI-->>Service: 200 OK (ModificationInfos[])
    Service-->>Caller: List<ModificationInfos> (converted or empty)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped through loops, then found a trail,
All UUIDs bundled, no more detail frail.
One tidy GET across the glade so wide,
Returned a list where scattered bits now bide.
I thump a happy paw — compact and spry.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: consolidating multiple REST calls into a single batched call to retrieve modifications.
Description check ✅ Passed The description is related to the changeset, explaining the purpose of consolidating modifications into one REST call and noting a related PR dependency.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java`:
- Around line 39-42: The queryParam call using modificationsUuids may be bound
to the varargs overload and not expand the list into repeated uuids=...
parameters; update the UriComponentsBuilder usage (the UriComponentsBuilder call
that builds the path with NETWORK_MODIFICATION_SERVER_API_VERSION and the
queryParam("uuids", modificationsUuids) invocation) to explicitly expand the
collection—either by passing the list elements (e.g., spread/iterate) or casting
to a Collection (e.g., (Collection<?>) modificationsUuids) so that queryParam
produces repeated uuids entries; ensure the onlyMetadata queryParam remains
unchanged.
🧹 Nitpick comments (2)
monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java (1)

38-46: Avoid remote call for empty UUID lists.

If modificationsUuids is empty or null, this builds a URL like ...?uuids= and still calls the server. Consider short‑circuiting to avoid unintended server behavior and wasted I/O.

♻️ Suggested guard
     public List<ModificationInfos> getModifications(List<UUID> modificationsUuids) {
+        if (modificationsUuids == null || modificationsUuids.isEmpty()) {
+            return List.of();
+        }
         String path = this.networkModificationServerBaseUri + UriComponentsBuilder.fromPath(DELIMITER + NETWORK_MODIFICATION_SERVER_API_VERSION + DELIMITER +
                 "network-composite-modifications" + DELIMITER + "network-modifications")
             .queryParam("uuids", modificationsUuids)
monitor-worker-server/src/test/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestServiceTest.java (1)

63-81: Use queryParam() matcher for order‑independent query parameter assertions.

Lines 65 and 80 assert the full URL string; query parameter ordering changes will break the test even if behavior is correct. Use MockRestRequestMatchers.queryParam() instead for robust, order‑independent matching.

✅ More robust matcher
-            .andExpect(MockRestRequestMatchers.requestTo("http://network-modification-server/v1/network-composite-modifications/network-modifications?uuids=" + MODIFICATION_1_UUID + "&uuids=" + MODIFICATION_2_UUID + "&onlyMetadata=false"))
+            .andExpect(MockRestRequestMatchers.requestTo("http://network-modification-server/v1/network-composite-modifications/network-modifications"))
+            .andExpect(MockRestRequestMatchers.queryParam("uuids", MODIFICATION_1_UUID.toString(), MODIFICATION_2_UUID.toString()))
+            .andExpect(MockRestRequestMatchers.queryParam("onlyMetadata", "false"))
-        server.expect(MockRestRequestMatchers.method(HttpMethod.GET))
-            .andExpect(MockRestRequestMatchers.requestTo("http://network-modification-server/v1/network-composite-modifications/network-modifications?uuids=" + MODIFICATION_ERROR_UUID + "&onlyMetadata=false"))
+        server.expect(MockRestRequestMatchers.method(HttpMethod.GET))
+            .andExpect(MockRestRequestMatchers.requestTo("http://network-modification-server/v1/network-composite-modifications/network-modifications"))
+            .andExpect(MockRestRequestMatchers.queryParam("uuids", MODIFICATION_ERROR_UUID.toString()))
+            .andExpect(MockRestRequestMatchers.queryParam("onlyMetadata", "false"))

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@monitor-worker-server/src/main/java/org/gridsuite/monitor/worker/server/services/NetworkModificationRestService.java`:
- Around line 38-46: In getModifications in NetworkModificationRestService,
guard against a null or empty modificationsUuids before building the URI: if
modificationsUuids is null or modificationsUuids.isEmpty(), immediately return
List.of() to avoid NPE from modificationsUuids.toArray() and skip the network
call; otherwise proceed to build the path (using
networkModificationServerBaseUri and UriComponentsBuilder) and call
networkModificationServerRest.getForObject as before. Ensure the short-circuit
uses the same return type (List<ModificationInfos>) and keeps the existing
behavior for non-empty input.

FranckLecuyer and others added 4 commits January 28, 2026 14:32
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Copy link

@thangqp thangqp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests pass for the normal case.
However, if the composite modification is deleted, the worker run does not stop. This behavior needs to be revisited.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2026

@FranckLecuyer FranckLecuyer merged commit 2e3181e into main Feb 4, 2026
4 checks passed
@FranckLecuyer FranckLecuyer deleted the get_all_modifications_in_only_one_rest_call branch February 4, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants